local qingqi = fk.CreateSkill{
  name = "lz__qingqi",
}

Fk:loadTranslationTable{
  ["lz__qingqi"] = "倾器",
  [":lz__qingqi"] = "回合结束时，你可明置任意张手牌，若数量大于上次，移动场上一张牌，当宝物牌进入你装备区后，你重置花色数。",
  ["#lz__qingqi-show"] = "倾器：你可以明置任意张手牌。",
  ["@lzsj__qingqi"] = "倾器",

  ["$lz__qingqi1"] = "若不能流芳百世，遗臭万年又何妨？",
  ["$lz__qingqi2"] = "废立由心非僭越，江东需我定乾坤！",
}

local ls = require "packages/lvshi/utility"
local DIY = require "packages/diy_utility/diy_utility"

qingqi:addEffect(fk.TurnEnd, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(qingqi.name) and target == player and not player:isKongcheng() then
      return ls.countSuits(player:getCardIds("h")) > player:getMark("@lzsj__qingqi")
    end
  end,
  on_cost = function (self, event, target, player, data)
    local cards = DIY.askToShowCards(player, {
      min_num = 1,
      max_num = player:getHandcardNum(),
      include_equip = false,
      skill_name = qingqi.name,
      prompt = "#lz__qingqi-show",
      cancelable = true,
    })
    if #cards > 0 then
      event:setCostData(self, cards)
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = event:getCostData(self)
    DIY.showCards(player, cards)
    if ls.countSuits(cards) > player:getMark("@lzsj__qingqi") then
      room:setPlayerMark(player, "@lzsj__qingqi", ls.countSuits(cards))
      local targets = room:askToChooseToMoveCardInBoard(player, {
        flag = "ej",
        skill_name = qingqi.name,
      })
      if #targets == 2 then
        room:askToMoveCardInBoard(player, {
          target_one = targets[1],
          target_two = targets[2],
          skill_name = qingqi.name,
        })
      end
    end
  end,
})

qingqi:addEffect(fk.AfterCardsMove, {
  can_refresh = function(self, event, target, player, data)
    if player:hasSkill(qingqi.name) then
      for _, move in ipairs(data) do
        if move.to and move.to == player and move.toArea == Card.PlayerEquip then
          for _, info in ipairs(move.moveInfo) do
            return Fk:getCardById(info.cardId).sub_type == Card.SubtypeTreasure
          end
        end
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@lzsj__qingqi", 0)
  end,
})

return qingqi